package com.wondersgroup.yly.service.impl;

import com.mseap.framework.dac.annotation.DataAccessResource;
import com.mseap.framework.dac.annotation.DataAccessSupport;
import com.mseap.framework.exception.BusinessException;
import com.wondersgroup.yly.dao.DemoDao;
import com.wondersgroup.yly.dto.DemoDTO;
import com.wondersgroup.yly.model.Demo;
import com.wondersgroup.yly.service.DemoService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

/**
 * @ClassName DemoServiceImpl
 * @Author liyunlei
 * @Date 2019-10-27 17:30
 */
@Slf4j
@DataAccessSupport
@Service
@Transactional
public class DemoServiceImpl implements DemoService {

    @DataAccessResource
    private DemoDao demoDao;


    @Override
    public Long insert(DemoDTO demoDTO) throws BusinessException {
        Demo demo = new Demo();
        BeanUtils.copyProperties(demoDTO, demo);
        demoDao.insert(demo);
        return demo.getId();
    }

    @Override
    public Long insertTry(DemoDTO demoDTO) {
        Demo demo = new Demo();
        BeanUtils.copyProperties(demoDTO, demo);
        demoDao.insertTry(demo);
        if(true){
            throw new BusinessException("400", "insert----------------BusinessException");
        }
        return demo.getId();
    }

    @Override
    public void insertConfirm(DemoDTO demoDTO, Long id) {
        demoDao.insertConfirm(id);
    }

    @Override
    public void insertCancel(DemoDTO demoDTO, Long id) {

    }

    @Override
    public void updateByPrimaryKey(DemoDTO demoDTO) throws BusinessException {
        Demo demo = new Demo();
        BeanUtils.copyProperties(demoDTO, demo);
        demoDao.updateByPrimaryKey(demo);
//        if(true){
//            throw new BusinessException("400", "--------------BusinessException");
//        }
    }
}
